package exercise;

import java.util.Scanner;

public class ComplexMultiplication {
    //1.复数乘法哔哩哔哩2020校园招聘
//输入两个表示复数的字符串，输出它们相乘的结果的字符串
//复数字符串用a+bi表示(a, b 为整数, i为虚数单位，i^2= -1)
//输入描述:
//输出描述:
//输入例子1:
//输出例子1:
//例子说明1:
//输入例子2:
//输出例子2:
//例子说明2:
//两个表示复数的字符串
//两个数相乘的结果的字符串
//1+2i
//2+1
//0+5i
//(1+2i)(2+i) = (2 + i + 4i + 2i * i) = 0 + 5i
//1+-2i
//3+4i
//11+-2i
//(1+-2i)(3+4i) = (3 + 4i - 6i - 8i * i) = 11+-2i
    public static int stringToInt(String s) {
        int num = 0;
        int flag = 1;
        for (int i = 0; i < s.length(); i++) {
//如果有负号，说明是负数
            if (s.charAt(i) == '-')
                flag = -1;
//只利用数字字符，i不使用
            else if (s.charAt(i) >= '0' && s.charAt(i) <= '9')
                num = num * 10 + (s.charAt(i) - '0');
        }
        return num * flag;
    }

    public static void main(String[] args) {
        String s1, s2;
        Scanner scanner = new Scanner(System.in);
        s1 = scanner.nextLine();
        s2 = scanner.nextLine();
//截取整数部分
        String s1First = s1.substring(0, s1.indexOf('+'));
        String s2First = s2.substring(0, s2.indexOf('+'));
//截取复数部分
//复数1
        String s1Second = s1.substring(s1.indexOf('+') + 1);
//复数2
        String s2Second = s2.substring(s2.indexOf('+') + 1);
//把字符串转换成整数
        int s1F = stringToInt(s1First);
        int s2F = stringToInt(s2First);
        int s1S = stringToInt(s1Second);
        int s2S = stringToInt(s2Second);
//整数部分
        int F = s1F * s2F - s1S * s2S;
//复数
        int S = s1F * s2S + s1S * s2F;
        System.out.println(F + "+" + S + "i");
    }
}

